package com.eclipse.e20200125_xml_properties_注解.注解;

import java.lang.annotation.Annotation;
import java.sql.Connection;
import java.sql.DriverManager;

//声明 默认给名字为value的元素赋值 
@Config("jdbc:mysql://localhost:3306/login?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&rewriteBatchedStatements=true")
public class JDBCUtils {

	public static Connection openConnection() throws Exception {
		//获取当前类的class类对象
		Class cls = JDBCUtils.class;
		//获取注解类的对象
		Config annotation = (Config) cls.getAnnotation(Config.class);

		//获取所有注解类信息
		Annotation[] annotations = cls.getAnnotations(); 
		for (Annotation temp :annotations) { System.out.println(temp); }
		

		// System.out.println(annotation);
		//返回数据库连接
		return DriverManager.getConnection(annotation.value(), annotation.username(), annotation.passwordr());
		

	}

}
